package spring.ai.example.spring_ai_demo;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai")
public class AIChatController {

    private ChatMemory chatMemory = new InMemoryChatMemory();

    /*public AIChatController(ChatClient.Builder builder) {

        this.chatClient = builder
                .defaultAdvisors(new MessageChatMemoryAdvisor(chatMemory, UUID.randomUUID().toString(), 10))
                .build();
    }*/
   

    private final ChatClient chatClient;

    public AIChatController(ChatClient.Builder builder) {
   
        this.chatClient = builder
                .build();
    }


    @GetMapping("/chat")
    public String chat(String message) {
   
        return this.chatClient.prompt()
                .user(message)
                .call()
                .content();
    }
}
